package com.qezhhnjy.demo.starter.config;

import com.qezhhnjy.demo.starter.service.ConditionService;
import com.qezhhnjy.demo.starter.service.DemoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * @author zhaoyangfu
 * @date 2021/5/15-12:24
 */
@Configuration
@EnableConfigurationProperties(DemoProperties.class)
@ConditionalOnProperty(prefix = "demo", name = "is-open", havingValue = "true")
@ConditionalOnClass(ConditionService.class)
@ConditionalOnBean({ConditionService.class})
@Slf4j
public class DemoConfig {

    @Resource
    private DemoProperties demoProperties;

    @Bean
    public DemoService demo() {
        log.warn("isOpen=>{}", demoProperties.getIsOpen());
        return new DemoService(demoProperties.getSayWhat(), demoProperties.getToWho());
    }
}
